home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 17705 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.3 KB  |  55 lines

  1. Path: news.sprintlink.net!datalytics!usenet
  2. From: Rob Stewart <stew@datalytics.com>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Circular Usage (forward declaration?)
  5. Date: Wed, 17 Apr 1996 00:40:17 -0400
  6. Organization: Datalytics, Inc.
  7. Message-ID: <31747631.5970@datalytics.com>
  8. References: <MRW.96Apr16184800@tobago.siemens.ch> <ltu3ykovzc.fsf@kitz.inferenzsysteme.informatik.th-darmstadt.de>
  9. NNTP-Posting-Host: 204.62.224.241
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 2.0 (WinNT; I)
  14.  
  15. Enno Sandner wrote:
  16. > In article <MRW.96Apr16184800@tobago.siemens.ch> mrw@tobago.siemens.ch (Waeckerlin Marc) writes:
  17. >    How do you realize this in C++:
  18. >    (the whole problem is much more complex, but it can be reduced to that)
  19. >    class A
  20. >    {
  21. >        B x;
  22. >    };
  23. >    class B
  24. >    {
  25. >        A x;
  26. >    };
  27. > There's no way -- use pointers or references instead, i.e. dynamicly
  28. > allocate the appropriate instance of class 'A' or class 'B'.
  29. >         Enno
  30.  
  31. Enno is correct, except you also need to forward declare one of 
  32. the classes:
  33.  
  34. class B;
  35.  
  36. class A
  37. {
  38.    B* px;
  39. };
  40.  
  41. class B
  42. {
  43.    A x;
  44. };
  45.  
  46. -- 
  47. Rob Stewart    | My opinions are generally my own.  They do
  48. Datalytics, Inc.| not necessarily reflect those of my employer.
  49.